using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_CapNhatDoanhNghiep : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"]);

            tbDoanhNghiepEntities doanhNghiep = tbDoanhNghiepBUS.GetByID(id);
            txt_MaDN.Text = doanhNghiep.MaDN.ToString();
            txt_TenDN.Text = doanhNghiep.TenDN.ToString();
            txt_Email.Text = doanhNghiep.Email.ToString();
            txt_DiaChi.Text = doanhNghiep.DiaChi.ToString();
            txt_DienThoai.Text = doanhNghiep.DienThoai.ToString();
        }
        catch
        {
            Response.Redirect("~/Admin/DanhSachDoanhNghiep.aspx");
        }

    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbDoanhNghiepEntities doanhNghiep = tbDoanhNghiepBUS.GetByID(id);
            doanhNghiep.TenDN = txt_TenDN.Text;
            doanhNghiep.Email = txt_Email.Text;
            doanhNghiep.DiaChi = txt_DiaChi.Text;
            doanhNghiep.DienThoai = txt_DienThoai.Text;
            tbDoanhNghiepBUS.Update(doanhNghiep);

            Response.Redirect("~/Admin/DanhSachDoanhNghiep.aspx");
            
        }
        catch
        {
            Response.Redirect("~/Admin/DanhSachDoanhNghiep.aspx");
        }
        Response.Redirect(Request.RawUrl);
    }
}
